package com.wolves.career.service.impl;

import com.wolves.career.entity.UserPermissionsAdmin;
import com.wolves.career.mapper.UserPermissionsAdminMapper;
import com.wolves.career.service.UserPermissionsAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 麦翔盛
 * @since 2021-10-19
 */
@Service
public class UserPermissionsAdminServiceImpl extends ServiceImpl<UserPermissionsAdminMapper, UserPermissionsAdmin> implements UserPermissionsAdminService {

    @Autowired
    private UserPermissionsAdminMapper userPermissionsAdminMapper;

    @Override
    public UserPermissionsAdmin check(String adminAccount, String adminPassword) {
        //先查找管理员是否存在
        UserPermissionsAdmin admin = userPermissionsAdminMapper.selectById(adminAccount);
        if (admin == null) {
            return null;
        }
        if (!admin.getAdminPassword().equals(adminPassword)) {
            return null;
        }
        return admin;
    }

    @Override
    public Boolean updatePassword(String adminAccount, String oldPassword, String newPassword) {
        if (oldPassword.equals(newPassword)){
            //新旧密码重复
            return false;
        }
        UserPermissionsAdmin admin = new UserPermissionsAdmin();
        admin.setAdminAccount(adminAccount);
        admin.setAdminPassword(newPassword);
        userPermissionsAdminMapper.updateById(admin);
        return true;
    }
}
